﻿using System;
using System.Diagnostics;
using System.Formats.Asn1;
using System.Text;
using XBD.MyBaseCode;
using CsvHelper;
using CsvHelper.Configuration;


namespace XBD.MyDataType
{

    internal class Program
    {


        static void Main(string[] args)
        {

            //Partial();
            /*
            string a = "时间就是金钱，我的朋友。";

            string str1 = null;
            string str2 = "";
            string str3 = "Hello, World!";

            string.IsNullOrEmpty(str3);
            if (string.IsNullOrEmpty(str1))
            {
                Console.WriteLine("str1 是 null 或空字串");
            }*/
            //CancellationTokenSource;

            //CsvDemo();
            //Range();
            //ManualResetEventDemo();
            //整型变量
            //int number;
            //number = 0;
            //Console.WriteLine(number);
            //字符串类型
            /*string hello = "Hello";
            string hello1 = "Kevin";
            // Console.WriteLine(hello + "Kevin");
            //字符串拼接
            string message = hello + "Kevin";
            //字符串格式化处理

            string name = "Kevin";
            int age = 18;

            //Console.WriteLine("My Name is {0}. I am {1} years old.", name, age);

            string message1 = "My Name is {0}. I am {1} years old.";

            string output = string.Format(message1, name, age);
            //Console.WriteLine(output);

            //字符串内嵌

            string message3 = $"My Name is {name}. I am {age} years old.";
            Console.WriteLine(message3);

            //原意字符串
            string message4 = "My Name is {0}.\n I am {1} years old.\n I am a developer";
            string message5 = $@"My Name is {name}.
                              I am {age} years old.
                              I am a developer";
            Console.WriteLine(message5);

            //System.String.
            string h = hello.ToUpper();
            Console.WriteLine(h);*/

            Console.Read();
        }


        public static void CsvDemo()
        {
            var persons = new List<Person>
            {
                new Person { Name = "张三", Age = 25, Gender = "男" },
                new Person { Name = "李四", Age = 30, Gender = "女" }
            };
            using (var writer = new StreamWriter(@".\StudentInfoFile.csv",false, Encoding.UTF8))
            using (var csv = new CsvWriter(writer, new CsvConfiguration(System.Globalization.CultureInfo.InvariantCulture)))
            {
                csv.WriteRecords(persons);
            }
            Console.WriteLine("CSV文件已成功写入！");

        }
        public class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public string  Gender { get; set; }
        }

        //局部类 partial的使用
        public static void Partial ()
        {

            instance.Point point = new();

            point.Delta = 15;

            point.PrintDelta();
        }

        public static void Range()
        {
            //_cts ??= new CancellationTokenSource();
            instance.Point point = new();
            point[0] = "aaa";
            Console.WriteLine(point["aaa"]);

            /* string[] words = new string[]
             {
                   "The",
                   "Quick",
                   "Cat",
                   "Dog"
             };

             // Console.WriteLine(words[^1]);
             //Console.WriteLine(words[^2]);
             //Range 范围 ,[开始位置..结束位置]
             Range p = 0..3;
             var list = words[p];
            //Console.WriteLine(list.Length);

             for (int i = 0; i <= list.Length ; i++)
             {
                 //Console.WriteLine(i);
                Console.WriteLine(words[i]);
             }*/
            Console.Read();
            return;
        }

        /// <summary>
        /// 测试时间
        /// </summary>
        public static void TestStopwatch()
        {
            //Stopwatch sw = new Stopwatch();

            var sw = Stopwatch.StartNew();

            Console.WriteLine(sw.ElapsedMilliseconds);

            // sw.Start();
            // StringBuilder  a = new StringBuilder(); 


            // for (int i = 0; i < 1000; i++)
            // {
            //     a.Append("111111111");
            // }
            //// Console.WriteLine(a);
            // Console.WriteLine((int)a.Capacity);


            // Console.WriteLine("测试完成");
            //sw.Stop();
            // long elapsedMilliseconds = sw.ElapsedTicks;

            // Console.WriteLine(elapsedMilliseconds);
        }
        /// <summary>
        /// 实例化
        /// </summary>
        /// 
        #region //计算两点间距离
        public static void PointA()
        {
            /* instance.Point a = new();
             a.DrawPoint(a);

             instance.Point b = new(2,2);

             double result = a.GetDistances(b);
             Console.WriteLine(result);*/

            //public private ,protected, internal
            /*instance.Point point = new()
            {
                X = 30
            };*/

            instance.Point point = new()
            {
                X = -30
            };

            Console.WriteLine(point.X);


            // Console.WriteLine(point.X);

            // Console.WriteLine(point.S = 5);

            //const readonly




        }
        #endregion


        /// <summary>
        /// ManualResetEvent测试
        /// </summary>

        public static void ManualResetEventDemo()
        {

            Signal.ManualResetEventDemo();

        }
        /// <summary>
        /// 引用传参数、值传参
        /// </summary>
        public static void getValue()
        {

            TestValue.getValue();

        }

        /// <summary>
        /// 循环类测试
        /// </summary>
        public static void loop()
        {
            //循环类测试
            loop loop = new loop();
            loop.test();

        }

    }
}
